<?php

namespace App\Models\Order;

use App\Libs\Base\Constant;

class PailebaoOrder extends \App\Libs\Base\BaseModel
{
    protected $__TABLE__ = 't_paile_pailebao';

    /**
     *    跳过检测了
     */
    public function beforeValidation()
    {
        self::skipValidation(['operate_info', 'refund_info', 'out_order_sn', 'pay_method'], $this);
    }

    public static function checkRefund($uid, $chargeSn)
    {
        $matchOrder = self::find([
            'conditions' => 'uid=?1 and order_sn=?2',
            'columns' => 'id,uid,order_sn,operate,money_num,order_status',
            'bind' => [1 => $uid, 2 => $chargeSn]
        ]);
        if (empty($matchOrder)) {
            return -10;
        } else {
            if ($matchOrder->order_status == '1' && $matchOrder->operate = '1') {   //order——status =1：支付，
                return $matchOrder;
            } else {
                return self::combineMsg($matchOrder);
            }
        }
    }


    public static function combineMsg($modelObj)
    {
        switch ($modelObj->operate) {
            case '1' :
                $operateText = '充值';
                break;
            case '0' :
                $operateText = '消费';
                break;
        }
        switch ($modelObj->order_status) {
            case '0' :
                $orderText = '未支付';
                break;
            case '1' :
                $orderText = '支付成功';
                break;
            case '9' :
                $orderText = '异常';
                break;

        }
        return '派乐宝订单：类型 ' . $operateText . '；状态 ' . $orderText;
    }

}
